package com.example.moonshine.baidumap.Service;

import android.content.Context;
import android.os.Looper;
import android.util.Log;

import com.example.moonshine.baidumap.Util.SureDialog;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import static android.content.ContentValues.TAG;

public class FragmentService {

    /**
     * Fragment下拉刷新
     *
     * @param context
     * @param refreshLayout
     */
    public void setDownRefresh(Context context,RefreshLayout refreshLayout)
    {

        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
//                init();
            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshlayout) {
                refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
            }
        });
        //设置 Header 为 贝塞尔雷达 样式
//        refreshLayout.setRefreshHeader(new BezierRadarHeader(this).setEnableHorizontalDrag(true));
//       设置 Footer 为 球脉冲 样式
//        refreshLayout.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale));
        refreshLayout.setRefreshHeader(new MaterialHeader(context));
        refreshLayout.setRefreshFooter(new ClassicsFooter(context));
    }


    /**
     *  展示任务信息
     * @param context
     */
    public void showDialog(Context context) {
        final SureDialog Dialog = new SureDialog(context);
        Dialog.setCanceledOnTouchOutside(true);
        Dialog.setTitle("消息提示");
        Dialog.setYesOnclickListener("确定", new SureDialog.onYesOnclickListener() {
            @Override
            public void onYesClick() {
                Log.i(TAG, "点击了确定");
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        Looper.prepare();
//                        DialogHtttpMap dialogHtttpMap = new DialogHtttpMap();
//                        try {
//                            String rusult = dialogHtttpMap.DialogSurehttp(token, MsgStaticdata.getManholeId());
//                            if (rusult.equals("10")) {
//                                Toast.makeText(getContext(), "任务接受成功，请赶紧完成任务", Toast.LENGTH_SHORT).show();
//                                //发送广播
//                                judgeTaskCode = 2;
//                                new Thread() {
//                                    @Override
//                                    public void run() {
//                                        handler.post(runnable);//子线程更新ui时，当子线程需要更新UI时，发消息通知主线程并将更新UI的任务post给主线程，让主线程来完成分内的UI更新操作
//                                    }
//                                }.start();
//
//                            } else {
//                                Toast.makeText(getContext(), "请求超时，请重试", Toast.LENGTH_SHORT).show();
//                            }
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                            Toast.makeText(getContext(), "服务器故障", Toast.LENGTH_SHORT).show();
//                        }
                        Looper.loop();
                    }
                }).start();
                Dialog.dismiss();
            }
        });
        Dialog.setNoOnclickListener("取消", new SureDialog.onNoOnclickListener() {
            @Override
            public void onNoClick() {

                Dialog.dismiss();
            }
        });
        Dialog.show();
    }
}
